﻿package core;

import java.util.Calendar;

public class DateConversion {

	/**
	 * 
	 * @param date
	 * @return
	 */
	public static Calendar getDateFromString(String date) {
		int year = getYear(date);
		int month = getMonth(date);
		int day = getDay(date);
		int hours = getHours(date);
		int minutes = getMinutes(date);
		int seconds = getSeconds(date);
		Calendar calendar = Calendar.getInstance();
		calendar.set(year, month, day, hours, minutes, seconds);
		return calendar;
	}

	/**
	 * 
	 * @param date
	 * @return
	 */
	public static int getYear(String date) {
		String result = date.substring(0, 4);
		return Integer.parseInt(result);
	}

	public static int getMonth(String date) {
		String result = date.substring(5, 7);
		return Integer.parseInt(result);
	}

	public static int getDay(String date) {
		String result = date.substring(8, 10);
		return Integer.parseInt(result);
	}

	public static int getHours(String date) {
		String result = date.substring(11, 13);
		return Integer.parseInt(result);
	}

	public static int getMinutes(String date) {
		String result = date.substring(14, 16);
		return Integer.parseInt(result);
	}

	public static int getSeconds(String date) {
		String result = date.substring(17);
		return Integer.parseInt(result);
	}

}
